package com.lh.blogTrivia.controller.admin;

import com.lh.blogCommon.result.LhR;
import com.lh.blogCommon.util.PageUtils;
import com.lh.blogTrivia.entity.MusicMemorizingEntity;
import com.lh.blogTrivia.service.MusicMemorizingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author lh0510
 * @email lh0510@gmail.com
 * @date 2021-03-09 10:31:46
 */
@Api(description = "音乐记忆管理")
@RestController
@RequestMapping("/admin/blogTrivia/musicmemorizing")
public class MusicMemorizingController {
    @Autowired
    private MusicMemorizingService musicMemorizingService;

    /**
     * 列表
     */
    @ApiOperation("列表")
    @GetMapping("/list")
    public LhR list(@RequestParam Map<String, Object> params){
        PageUtils page = musicMemorizingService.queryPage(params);

        return LhR.ok().data("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/info/{memorizingId}")
    public LhR info(@PathVariable("memorizingId") String memorizingId){
		MusicMemorizingEntity musicMemorizing = musicMemorizingService.getById(memorizingId);

        return LhR.ok().data("musicMemorizing", musicMemorizing);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    public LhR save(@RequestBody MusicMemorizingEntity musicMemorizing){
		musicMemorizingService.save(musicMemorizing);

        return LhR.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PutMapping("/update")
    public LhR update(@RequestBody MusicMemorizingEntity musicMemorizing){
		musicMemorizingService.updateById(musicMemorizing);

        return LhR.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public LhR delete(@RequestBody String[] memorizingIds){
		musicMemorizingService.removeByIds(Arrays.asList(memorizingIds));

        return LhR.ok();
    }

}
